<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加NFT</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/resource/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/resource/css/mylay.css">
</head>
<style>
    .layui-form-pane .layui-form-label{
        width: 200px;
    }
    .layui-form-pane .layui-input-block{
        margin-left:200px;
    }
</style>
<body>
    <div style="padding: 20px; background-color: #F2F2F2;">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <!-- <p style="color:red;">请填写账号后再上传，否则将导致失败</p>
                        <p style="color:red;">请在二维码图片显示后再点击确定提交</p>
                        <br /> -->
                        <form class="layui-form layui-form-pane" action="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">发行者</label>
                                <div class="layui-input-inline">
                                    <select name="uid" lay-verify="required" lay-search="">
                                        {foreach $users as $key=>$value }
                                        <option value="{$value.id}">{$value.username}</option>
                                        {/foreach}
                                    </select>
                                </div>
                                <div class="layui-form-mid layui-word-aux"></div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">NFT文件</label>
                                <div class="layui-input-inline">
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="file">
                                            <i class="layui-icon">&#xe67c;</i>上传
                                        </button>
                                        <div class="layui-upload-list">
                                            <img class="layui-upload-img" id="file_image" style="width:150px;">
                                            <p id="file_image_text"></p>
                                        </div>
                                    </div>
                                    <input type="hidden" name="file" id="file_input" value="" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">选择图片后自动上传</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">NFT名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" autocomplete="off" placeholder="请输入NFT名称" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">类型</label>
                                <div class="layui-input-inline">
                                    <select name="credit_type" lay-verify="required" lay-search="">
                                        {foreach $creditType as $key=>$value }
                                        <option value="{$value['id']}">{$value['name']}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">特性，请用英文逗号分隔</label>
                                <div class="layui-input-block">
                                    <textarea name="characteristic" placeholder="请输入特性，请用英文逗号分隔" class="layui-textarea"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">描述</label>
                                <div class="layui-input-block">
                                    <textarea name="content" placeholder="描述" class="layui-textarea"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item" style="margin-top: 40px;text-align: center;">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="nft_add">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

<script src="/resource/layuiadmin/layui/layui.js"></script>
<script src="/resource/js/manage/init_date.js"></script>
<script>
    layui.use(['layer', 'element', 'form', 'upload', 'table'], function() {
        var $ = layui.$
            ,layer   = layui.layer
            ,form    = layui.form
            ,upload  = layui.upload
            ,table   = layui.table;

        form.on('submit(nft_add)', function(data){
            $.ajax({
                url: "/manage/nft/nftAdd",
                data: data.field,
                type: "POST",
                dataType: "json",
                timeout: 15000,
                beforeSend: function(){
                    layer.load(1);
                },
                success: function(msg){
                    var alertStr = (msg == 1) ? '操作成功' : msg;
                    layer.msg(alertStr, {time: 2000}, function(){
                        if(msg==1){
                            parent.layer.closeAll();
                            parent.layui.table.reload('nft');
                        }
                    });
                },
                complete: function(){
                    layer.closeAll("loading");
                }
            });
            return false;
        });

        var cover_img_upload = upload.render({
            elem: '#file'
            ,url: '/manage/common/fileUpload'
            ,data: {

            }
            ,accept: 'images'
            ,acceptMime: 'image/*'
            ,exts: 'jpg|png|gif|bmp|jpeg'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#file_image').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code == 0){
                    return layer.msg(res.success);
                }
                //上传成功
                $("#file_input").val(res.success);
                return layer.msg('上传成功');
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#qrcode_image_text');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    cover_img_upload.upload();
                });
            }
        });
    })
</script>
</body>
</html>
